package cn.mugutu.webrtc.websocket.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import cn.mugutu.webrtc.websocket.WebSocketHander;
import cn.mugutu.webrtc.websocket.interceptor.HandshakeInterceptor;

/**
 * websocket配置类,在启动项目的时候就实例化了,
 * 并且执行了registerWebSocketHandlers方法,
 * 注册了websoket的处理类(WebSocketHander)
 * @author gan
 *
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer{

	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
		 registry.addHandler(new WebSocketHander(),"/rtc").addInterceptors(new HandshakeInterceptor()).setAllowedOrigins("*"); //支持websocket 的访问链接
         registry.addHandler(new WebSocketHander(),"/sockjs/echo").addInterceptors(new HandshakeInterceptor()).setAllowedOrigins("*").withSockJS(); //不支持websocket的访问链接
	}

	public WebSocketConfig() {
		
	}
}
